
/*
 * @Autor: Mr Lu
 * @Version: 1.0
 * @Date: 2019-12-03
 * @LastEditors: OBKoro1
 * @LastEditTime: 2019-12-17
 * @Description:  选择项目
 */
 <template>
  <div id="RandomSelectProject" class="p-box">
    <div class="p-return" style="margin-bottom:0">
      <mu-appbar color="primary" class="lan-header">
        <mu-button icon slot="left" v-close>
          <i class="iconfont angle-left iconangle-left"></i>
          <span class="lan-header-back">返回</span>
        </mu-button>随机测量
      </mu-appbar>
    </div>
    <div class="p-content">
      <mTree
        v-show="tree.data.length"
        :data="tree.data"
        :props="tree.defaultProps"
        :clickableConditions="tree.clickableConditions"
        @click="skipPage"
      ></mTree>
      <NoData v-if="!tree.data.length&&!tree.loading" />
      <!-- <div class="flex column" style="height:100%">
        <div class="selectProject">
          <mu-form
            ref="form"
            :model="form"
            class="mu-lan-form"
            :label-position="'left'"
            label-width="28%"
          >
            <mu-form-item label="项目名称">
              <mu-text-field
                v-model="form.projectName"
                container="bottomSheet"
                :readonly="true"
                @click="showOrgModal"
              ></mu-text-field>
              <i class="iconfont angle-left iconangle-right"></i>
            </mu-form-item>
          </mu-form>
        </div>
        <div class="flex-1">
         
        </div>
      </div>-->
    </div>
    <Org
      ref="org"
      v-model="org"
      @change="orgChange"
      :open="openOrg"
      title="选择项目"
      orgType="currOrgProject"
      @close="closeOrgDialog"
      @confirm="confirmOrgDialog"
    ></Org>
  </div>
</template>

<script>
import mTree from "@/tree/mTree";
import { MessageBox } from "mint-ui";

import Org from "@/select/org/Org.vue";
export default {
  name: "RandomSelectProject",
  components: {
    Org,
    mTree
  },
  props: {},
  data() {
    return {
      openOrg: false,
      form: {
        projectName: "",
        projectId: ""
      },
      org: [
        {
          label: "",
          value: "",
          disabled: false,
          checked: false,
          hasChecked: true,
          hasChildren: true
        }
      ],
      tree: {
        loading: false,

        defaultProps: {
          id: "id",
          name: "name",
          children: "children"
        },
        clickableConditions: {
          all: {
            //所有的是否可以点击
            enable: true
          },
          part: {
            //部分的可以点击的条件
            prop: "orgType",
            value: [1]
          }
        },
        data: []
      }
    };
  },
  computed: {},
  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (from.name == "StartEdit") {
        vm.$nextTick(() => {
          vm.$refs.dialogAddTask.openMe();
        });
      }
    });
  },
  created() {
    this.org = [
      {
        label: this.$A.GS("orgInfo")["orgName"],
        value: this.$A.GS("orgInfo")["orgId"],
        disabled: false,
        checked: false,
        hasChecked: true,
        hasChildren: true
      }
    ];
    if (this.$A.GS("orgInfo")["type"] == 1) {
      this.openOrg = false;
      this.form = {
        projectId: this.$A.GS("orgInfo")["orgId"],
        projectName: this.$A.GS("orgInfo")["orgName"]
      };
      console.log(this.form);
      this.initPage();
    } else {
      this.openOrg = true;
    }
  },
  mounted() {},
  watch: {},
  methods: {
    initPage() {
      this.tree.loading = true;
      this.$openLoading();
      let params = {
        orgId: this.form.projectId
      };
      this.$A.Go("get", "/safety/projectArea/tree", params).then(
        response => {
          this.$closeLoading();
          this.tree.loading = false;
          this.tree.data =
            response.body && response.body.length ? response.body : [];
        },
        err => {
          this.$closeLoading();
          this.tree.loading = false;
          console.log(err);
        }
      );
    },
    //进入平面图标点
    skipPage(treeRowData) {
      console.log(this.form);
      this.$router.push({
        name: "RandomMarkPoint",
        query: {
          projectId: this.form.projectId,
          projectName: this.form.projectName,
          areaId: treeRowData.id,
          areaName: treeRowData.name
        }
      });
    },
    //组织change事件
    orgChange(ev) {
      this.form = {
        projectId: ev[0].value,
        projectName: ev[0].label
      };
      this.initPage();
    },
    //点击选择项目的返回按钮
    closeOrgDialog() {
      this.$router.back();
    },
    showOrgModal() {
      this.openOrg = true;
    },
    //关闭选择项目的弹出框
    confirmOrgDialog() {
      this.openOrg = false;
    }
  },
  destroyed() {}
};
</script>
<style lang="less">
#RandomSelectProject {
  .p-content {
    .lan-nodata {
      height: 100%;
      background: #fff;
    }
  }
}
</style>
